package cn.easier.activity.console.service.impl;

import cn.easier.activity.console.repository.ActivityCouponCodeRepository;
import cn.easier.activity.console.service.ActivityCouponCodeService;
import cn.easier.activity.web.entity.ActivityCouponCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 券码ServiceImpl
 */
@Service
@Transactional
public class ActivityCouponCodeServiceImpl implements ActivityCouponCodeService {

    @Autowired
    ActivityCouponCodeRepository activityCouponCodeRepository;

    @Override
    public ActivityCouponCode save(ActivityCouponCode activityCouponCode) {
        return activityCouponCodeRepository.save(activityCouponCode);
    }

    @Override
    public List<ActivityCouponCode> saveList(List<ActivityCouponCode> activityCouponCodeList) {
        return activityCouponCodeRepository.save(activityCouponCodeList);
    }

    @Override
    public ActivityCouponCode findOne(Integer id) {
        return activityCouponCodeRepository.findOne(id);
    }

    @Override
    public int countByAvailable(Integer activityPrizeId, Boolean available) {
        return activityCouponCodeRepository.countByAvailable(activityPrizeId, available);
    }

    @Override
    public List<ActivityCouponCode> findList(Integer activityPrizeId) {
        return activityCouponCodeRepository.findActivityCouponCodesByActivityPrizeId(activityPrizeId);
    }

    @Override
    public int deleteByBatch(String batch, String user) {
        return activityCouponCodeRepository.deleteByBatch(batch, user);
    }

    @Override
    public Boolean delete(Integer id, String user) {
        return activityCouponCodeRepository.deleteFlag(id, user) > 0 ? true : false;
    }

    @Override
    public ActivityCouponCode findByOne(String user, Integer id) {
        return activityCouponCodeRepository.findByIdAndUser(id,user);
    }

    @Override
    public Boolean deleteByAdmin(Integer id) {
        return activityCouponCodeRepository.deleteByFlag(id) >0 ? true:false;
    }
}
